﻿using System;
using System.Linq.Expressions;
using System.Collections.Generic;

namespace Caramel.Web.Mvc.Validation
{
	public class ClassModelValidator<T> : IClassValidator
	{
		public ClassModelValidator()
		{
			this.Properties = new Dictionary<string, PropertyModelValidator>();
		}

		public IDictionary<string, PropertyModelValidator> Properties { get; private set; }

		public PropertyModelValidator Rule(Expression<Func<T, object>> expression)
		{
			var name = expression.GetProperty().Name;

			if (!this.Properties.ContainsKey(name))
			{
				this.Properties.Add(name, new PropertyModelValidator());
			}

			return this.Properties[name];
		}
	}
}
